import matplotlib.pyplot as plt
from wordcloud import WordCloud
import requests
import re
import jieba

data = requests.get(url="http://api.bilibili.com/x/v1/dm/list.so?oid=201056987")
data.encoding = 'utf-8'
pat = re.compile(r"(?<=>)[\u4e00-\u9fa5]+(?=<)")
res = pat.findall(data.text)
tem = ""
data_str = tem.join(res)
data_changed = jieba.cut(data_str, cut_all=True)
tem = " "
data_end = tem.join(data_changed)
wd = WordCloud(max_words=2000, font_path='simfang.ttf')
result = wd.generate(data_end)
plt.figure()
plt.imshow(result)
plt.axis('off')
plt.show()